<template>
  <van-icon
    :color="value ? '#e22829' : '#777'"
    :name="value ? 'good-job' : 'good-job-o'"
    @click="deleteFollowed"
  />
</template>

<script>
import { addArticleLikings, deleteArticleLikings } from '@/api/article.js'
export default {
  name: 'LikingsIndex',
  data () {
    return {

    }
  },
  props: {
    value: {
      type: Number,
      required: true
    },
    artId: {
      type: [Number, Object],
      required: true
    }
  },
  methods: {
    // 文章点赞
    async deleteFollowed () {
      try {
        if (this.value) {
          await deleteArticleLikings(this.artId)
          this.$emit('input', 0)
        } else {
          await addArticleLikings(this.artId)
          this.$emit('input', 1)
        }
        this.$toast.success('操作成功')
      } catch (err) {
        this.$toast.success('操作失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>
</style>
